/**
 * 贪心算法-最大子数组和-力扣53
 */

public class Practice_13 {
    public static void main(String[] args) {
        int[]  nums = {-2,1,-3,4,-1,2,1,-5,4};

        int max = maxSubArray(nums);
        System.out.println(max);
    }
    public  static int maxSubArray(int[] nums) {
        int result=Integer.MIN_VALUE;
        int count=0;
        for(int i=0;i<nums.length;i++){

            count=count+nums[i];
            if(count>result){
                result=count;
            }
            if(count<0){
                count=0;
            }
        }
        return result;
    }


}
